import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;

import javax.swing.JPanel;

public class MyPanel extends JPanel {
	private BufferedImage img;
	private ImageHandler handler;

	public MyPanel(ImageHandler handler) {
		this.img = handler.getImage();
		this.handler = handler;

		this.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				int x = e.getX();
				int y = e.getY();
				doWithXY(x, y);
			}
		});
	}

	@Override
	public void paintComponent(Graphics g) {
		g.drawImage(img, 0, 0, img.getWidth(), img.getHeight(), null);
	};

	private void doWithXY(int x, int y) {
		int[] rgb = handler.getRGB(x, y);
		boolean isRoad = handler.judgeRGB(x, y, handler.BLACK);
		System.out.println("red:" + rgb[0] + " green:" + rgb[1] + " blue:"
				+ rgb[2] + " " + isRoad);
	}
}
